package com.lovo.ssc.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lovo.csc.service.IAuditService;
import com.lovo.psc.service.IPscUserService;
import com.lovo.ssc.entity.BuyPlan;
import com.lovo.ssc.entity.SysGoods2;
import com.lovo.ssc.service.IBuyPlanService;
import com.lovo.ssc.service.ISysGoods2Service;
import com.lovo.sscsys.dto.BuyPlanMQDto;
import com.lovo.sscsys.dto.SysGoodsTotalMQDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
 * <p>
 * 采购表 前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-07
 */
@RestController
@RequestMapping("/buyplan")
@Slf4j
@Api(tags = "采购计划控制器-张海军")
public class BuyPlanController {
    //1.本地采购计划
    @Autowired
    IBuyPlanService service;
    //2.总库存接口
    @Autowired
    ISysGoods2Service sysGoods2Service;

    @Autowired
    IAuditService iAuditService;

    @Autowired
    IPscUserService pscUserService;
    

    /**
     * 1.查询全部采购计划
     *
     * @return
     */

    @ApiOperation(value = "查询全部采购计划")
    @GetMapping("findAllPlan")
    public List<BuyPlan> findAllPlan() {
        List<BuyPlan> list=   service.list();
        return list;
    }

    /**
     * 2.添加采购计划
     *
     * @return
     */
    @ApiOperation(value = "新增采购计划")
    @PostMapping("addPlan")
    public String addPlan(BuyPlanMQDto dto ) {
        service.addAutoPlan(dto);
        return "ok";
    }
    /**
     * 3.修改库存商品阈值
     *
     * @return
     */
    @ApiOperation(value = "修改库存商品阈值")
    @PutMapping("updateScope/{id}/{newScope}")
    public String updateScope(@PathVariable("id")Integer id, @PathVariable("newScope")Integer newScope) {
     sysGoods2Service.updateScope(id,newScope);
        return "ok";
    }
    /**
     * 4.测试上架出库
     *
     * @return
     */
    @ApiOperation(value = "测试上架出库")
    @PutMapping("testOutStore")
    public String testOutStore(String goodsCode,String batch,Integer num) {
        sysGoods2Service.outStorage(goodsCode,batch,num);
        return "ok";
    }
    /**
     * 5.测试退货入库
     *
     * @return
     */
    @ApiOperation(value = "测试退货入库")
    @PutMapping("testInStore")
    public String testInStore(String goodsCode,String batch,Integer num) {
        sysGoods2Service.inStorageCauseByReturn(goodsCode,batch,num);
        return "ok";
    }
    /**
     * 6.测试查询未定价商品
     *
     * @return
     */
    @ApiOperation(value = "测试查询未定价商品")
    @GetMapping("testFindByState")
    public List<SysGoodsTotalMQDto> testFindByState() {
        QueryWrapper qw=new QueryWrapper();
        qw.eq("state","未定价");
        List<SysGoods2> list  =sysGoods2Service.list(qw);
        List<SysGoodsTotalMQDto> list1=new ArrayList<>();
        for (SysGoods2 sysGoods2 : list) {
            SysGoodsTotalMQDto sysGoodsTotalMQDto=new SysGoodsTotalMQDto();
            BeanUtils.copyProperties(sysGoods2, sysGoodsTotalMQDto);
            list1.add(sysGoodsTotalMQDto);
        }
        return list1;
    }

    /**
     * feign审核
     */
    @GetMapping("testTwo")
    public void testTwo(String code,String info){
        iAuditService.updateOrderState(code,info,"张三丰");
}

    /**
     * feign供应商
     */
    @PutMapping("testCheck")
    public void testCheck(String code,String info){
        pscUserService.updateState(code,info);
        log.info("--------测试成功---------");
    }


}
